﻿using AngryManagementMayhem.Content.Textures.Map;
using AngryManagementMayhem.Controller.Map;
using Transformable_Engine_v2.Engine.GameObjects.Containers;
using Transformable_Engine_v2.Engine.Transformable_Math.Geometry;

namespace AngryManagementMayhem.Content.Map.TestMapScreens
{
    public class TestScreen00 : BaseScreen
    {
        public override void Initialize()
        {
            AddBlock(new TE_Rectangle(0, 6, 4, 3));
            AddBlock(new TE_Rectangle(4, 7, 4, 3));
            AddBlock(new TE_Rectangle(8, 8, 4, 3));
            AddBlock(new TE_Rectangle(12, 9, 4, 3));
            AddBlock(new TE_Rectangle(16, 10, 4, 3));
            AddBlock(new TE_Rectangle(20, 11, 2, 3));

            AddBlock(new TE_Rectangle(0, 0, 2, 5 ));

            base.Initialize();
        }

        void AddTile(int positionX, int positionY, CollisionDefinition.CollisionTypeList collisionType,
                        CollisionDefinition.SpecialTileEffectList specialEffect = CollisionDefinition.SpecialTileEffectList.None)
        {
            AddChildren(new ImageContainer
                {
                    Position = new TE_Vector2(positionX * CollisionDefinition.CollisionSize, positionY * CollisionDefinition.CollisionSize),
                    Sprite = TestMapSpriteSheet.GetSprite(TestMapSpriteSheet.SpriteList.Tile)
                });
            AddMapCell(positionX, positionY, new CollisionDefinition(collisionType, CollisionDefinition.CellTypeList.Terrain, specialEffect));
        }

        void AddBlock(TE_Rectangle area)
        {
            for (int i = 1; i < area.Width - 1; i++) 
            {
                AddTile((int) (area.X + i), (int) area.Y, CollisionDefinition.CollisionTypeList.Floor);
                AddTile((int) (area.X + i), (int) (area.Bottom - 1), CollisionDefinition.CollisionTypeList.Ceiling);
            }
            for (int i = 1; i < area.Height - 1; i++) {
                AddTile((int) area.X, (int) (area.Y + i), CollisionDefinition.CollisionTypeList.Left);
                AddTile((int) (area.Right - 1), (int) (area.Y + i), CollisionDefinition.CollisionTypeList.Right);
            }

            AddTile((int) area.X, (int) area.Y, CollisionDefinition.CollisionTypeList.Floor | CollisionDefinition.CollisionTypeList.Left);
            AddTile((int) area.Right - 1, (int) area.Y, CollisionDefinition.CollisionTypeList.Floor | CollisionDefinition.CollisionTypeList.Right);
            AddTile((int) area.X, (int) area.Bottom - 1, CollisionDefinition.CollisionTypeList.Ceiling | CollisionDefinition.CollisionTypeList.Left);
            AddTile((int) area.Right - 1, (int) area.Bottom - 1, CollisionDefinition.CollisionTypeList.Ceiling | CollisionDefinition.CollisionTypeList.Right);
        }
    }
}